#define _GNU_SOURCE//如果不定义这个，gettid()会报错
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>

void *first_thread(void *arg)
{
    printf("first线程(%d)开始执行,\n",gettid());
    return NULL;
}

void *second_thread(void *arg)
{
    printf("second线程(%d)开始执行,\n",gettid());
}

int main(int argc, char *argv[])
{
    printf("main 线程(%d)开始执行\n",gettid());
    pthread_t first_pt , second_pt;

    //创建第一个线程
    pthread_create(&first_pt,NULL,first_thread,NULL);
    //创建第二个线程
    pthread_create(&second_pt,NULL,second_thread,NULL);

    printf("main 线程(%d)继续执行  first_pt=%ld , second_pt=%ld\n",
    gettid(), first_pt,second_pt);

    //等待两个线程执行完毕
    pthread_join(first_pt,NULL);
    pthread_join(second_pt,NULL);

    printf("main 线程(%d)结束执行\n",gettid());

    return 0;
}